#!/usr/bin/env bash

:<<description

功能：自动生成 unit 执行计划
描述：

description

#设置脚本异常立即退出
set -e
#获取当前脚本名
script=$0
scriptBase=$(basename ${script})
scriptDir=$(cd $(dirname $0); pwd)
workDir=${scriptDir}
planDir=${1:-${workDir}/plan/unit}

items=(
'hi:gitClone'
'hi:gitCloneForce'
'hi:gitDiff'

'hi:pack'
'hi:collect'
'hi:unpack'
'hi:unpackForce'
'hi:todo'
'hi:undo'
'hi:redo'
'hi:backup'
'hi:update'
'hi:updateForce'
'hi:init'
'hi:initForce'
'hi:rollbackForce'
'hi:rollback'
'hi:sshSend'
'hi:sshSendForce'
'hi:sshUnpack'
'hi:sshUnpackForce'
'hi:sshTodo'
'hi:sshUndo'
'hi:sshRedo'
'hi:sshBackup'
'hi:sshUpdate'
'hi:sshUpdateForce'
'hi:sshInit'
'hi:sshInitForce'
'hi:sshRollbackForce'
'hi:sshRollback'

'hiNginx:gitClone'
'hiNginx:gitCloneForce'
'hiNginx:gitDiff'

'hiNginx:pack'
'hiNginx:collect'
'hiNginx:unpack'
'hiNginx:unpackForce'
'hiNginx:todo'
'hiNginx:undo'
'hiNginx:redo'
'hiNginx:backup'
'hiNginx:backupConfig'
'hiNginx:update'
'hiNginx:updateConfig'
'hiNginx:updateForce'
'hiNginx:updateConfigForce'
'hiNginx:init'
'hiNginx:initConfig'
'hiNginx:initForce'
'hiNginx:initConfigForce'
'hiNginx:rollback'
'hiNginx:rollbackConfig'
'hiNginx:rollbackForce'
'hiNginx:rollbackConfigForce'
'hiNginx:sshSend'
'hiNginx:sshSendForce'
'hiNginx:sshUnpack'
'hiNginx:sshUnpackForce'
'hiNginx:sshTodo'
'hiNginx:sshUndo'
'hiNginx:sshRedo'
'hiNginx:sshBackup'
'hiNginx:sshBackupConfig'
'hiNginx:sshUpdate'
'hiNginx:sshUpdateConfig'
'hiNginx:sshUpdateForce'
'hiNginx:sshUpdateConfigForce'
'hiNginx:sshInit'
'hiNginx:sshInitConfig'
'hiNginx:sshInitForce'
'hiNginx:sshInitConfigForce'
'hiNginx:sshRollback'
'hiNginx:sshRollbackConfig'
'hiNginx:sshRollbackForce'
'hiNginx:sshRollbackConfigForce'

'hiNginx:status'
'hiNginx:terminate'
'hiNginx:startup'
'hiNginx:restart'
'hiNginx:reload'
'hiNginx:sshStatus'
'hiNginx:sshTerminate'
'hiNginx:sshStartup'
'hiNginx:sshRestart'
'hiNginx:sshReload'

'hiFlask:gitClone'
'hiFlask:gitCloneForce'
'hiFlask:gitDiff'

'hiFlask:pack'
'hiFlask:collect'
'hiFlask:unpack'
'hiFlask:unpackForce'
'hiFlask:todo'
'hiFlask:undo'
'hiFlask:redo'
'hiFlask:backup'
'hiFlask:update'
'hiFlask:updateForce'
'hiFlask:init'
'hiFlask:initForce'
'hiFlask:rollbackForce'
'hiFlask:rollback'
'hiFlask:sshSend'
'hiFlask:sshSendForce'
'hiFlask:sshUnpack'
'hiFlask:sshUnpackForce'
'hiFlask:sshTodo'
'hiFlask:sshUndo'
'hiFlask:sshRedo'
'hiFlask:sshBackup'
'hiFlask:sshUpdate'
'hiFlask:sshUpdateForce'
'hiFlask:sshInit'
'hiFlask:sshInitForce'
'hiFlask:sshRollbackForce'
'hiFlask:sshRollback'

'hiFlask:status'
'hiFlask:terminate'
'hiFlask:startup'
'hiFlask:restart'
'hiFlask:sshStatus'
'hiFlask:sshTerminate'
'hiFlask:sshStartup'
'hiFlask:sshRestart'
'hiFlask:sshGitClone'
'hiFlask:sshGitCloneForce'
'hiFlask:sshGitDiff'
)


function generateUnitPlan(){
    mkdir -p ${planDir}
    for item in ${items[@]}; do
        resource=$( echo ${item} | cut -d ':' -f 1 )
        action=$( echo ${item} | cut -d ':' -f 2 )
        echo -n "${action}: ${resource}" > "${planDir}/${action}-${resource}.lst"
    done
}

generateUnitPlan




